<?php

namespace Entity;

class FileStat
{
    protected
    
    $filelist,
    $summary = array(),
    $output = array();
    
    function __construct()
    {
        $this->summary = array(
                    'totalfiles' => 0,
                    'totalsize' => 0,
                    'largestsize' => 0,
                );
                
        $this->filelist = array();
        
        unset($list);
    }
    
    function __get($key) { return $this->$key; }
    
    public function stat($files)
    {
        $sizer = new Sizer;
        
        foreach($files as $key => $file)
        {
            $size = filesize($file);
            $this->filelist [] = array(
                            'name' => $file,
                            'size' => $sizer($size),
                        );
                        
            $totals [] = $size;
        }
        
        $this->output['files'] = $this->filelist;
        $this->output['filetotals'] = $sizer(array_sum($totals));
        
        $this->summary['totalfiles'] = sizeof($files);
        $this->summary['totalsize'] = $this->output['filetotals'];
        $this->summary['largestsize'] = $sizer(max($totals));
        
        unset($sizer, $files, $key, $file, $size, $totals);
    }
    
    function __invoke()
    {
        $args = func_get_args();
        $this->stat($args[0]);
    }
}
